define(["dojo/_base/declare", "../widgets/baseWidget/BaseWidget",
        "dojo/_base/lang",
        "dojo/on",
        "dojo/query",
        "dojo/dom-style",
        "dojo/dom-class",
        "dojo/keys",
        "dojo/topic",
        "dojo/text!./templates/Template.html"],
        function(declare,BaseWidget,lang,on,query, domStyle,domClass,keys,topic,template){
	return declare([BaseWidget],{
    	//模板页面
        templateString : template,
        selector:"havenotset",
        _control:null,
        _isExpand:undefined,
        expandState:"left",
        initExpand:true,
        left:null,
        right:null,
        top:null,
        bottom:null,
        _stateMap:{"left":"right","right":"left","top":"bottom","bottom":"top"},
        
        //构造
        constructor : function(args) {
        	this.inherited(arguments);
            this.expandState=args.expandState;
            this.left=args.left;
            this.right=args.right;
            this.top=args.top;
            this.bottom=args.bottom;
            this.eventName=args.eventName;
            this.id=args.id;
        },
        
        //组件初始化方法
        postCreate : function() {
        	this.inherited(arguments);
        	this.init();
        	this._control=dojo.query(this.selector);// ???
        	this.setExpand(this.initExpand);
        	this.addEvents();
        },
        
        startup:function(){
        	this.inherited(arguments);
        },
        
        init:function(){
        	domStyle.set(this.domNode,"left",this.left);
        	domStyle.set(this.domNode,"right",this.right);
        	domStyle.set(this.domNode,"top",this.top);
        	domStyle.set(this.domNode,"bottom",this.bottom);
        } ,
        
        setExpand:function(expand){
        	if(expand!==this._isExpand){
        		var negState=this._stateMap[this.expandState];
        		dojo.removeClass(this.domNode,this._isExpand?this.expandState:negState);
        		dojo.addClass(this.domNode,expand?this.expandState:negState);
        		this._control.removeClass((this._isExpand?"move_":"moved_")+this.expandState);
        		this._control.addClass((expand?"move_":"moved_")+this.expandState);
        		this._isExpand=expand;
        	}
        },
        
        addEvents:function(){
        	
        	topic.subscribe("ChangeArrowDirection", lang.hitch(this, this.ChangeArrowDirection));
        	on(this.domNode,"click",dojo.hitch(this,this.clickHandle));
        },
        
        ChangeArrowDirection:function(args){
        	if (this.id==args.id){
        		this.setExpand(args.expand);
        	}
        },
        
        clickHandle:function(){
        	this.setExpand(!this._isExpand);
        	if (this.eventName){
        		topic.publish(this.eventName, {expand:this._isExpand});
        	}
        },
        
        destroy:function(){
        	this.inherited(arguments);
        } 
	})
})